/*
 * @Author: Smthie Smthie@qq.com
 * @Date: 2024-05-13 10:06:44
 * @LastEditors: Smthie Smthie@qq.com
 * @LastEditTime: 2024-05-21 09:40:22
 * @FilePath: \ProtocolTool\electron.vite.config.ts
 */
import { resolve } from 'path'
import { defineConfig, loadEnv, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
// import Components from 'unplugin-vue-components/vite'
// import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'

import { prismjsPlugin } from 'vite-plugin-prismjs'

export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd())
  return {
    main: {
      plugins: [externalizeDepsPlugin()]
    },
    preload: {
      plugins: [externalizeDepsPlugin()]
    },
    renderer: {
      resolve: {
        alias: {
          '@': resolve('src/renderer/src')
        }
      },
      plugins: [
        vue(),
        AutoImport({
          // 自动导入 Vue vue-router 相关函数
          imports: ['vue', 'vue-router']
          // // 自动导入 AntDesignVue 相关函数
          // resolvers: [AntDesignVueResolver()]
          // dts: path.resolve(__dirname, "auto-imports.d.ts"),
        }),
        prismjsPlugin({
          languages: 'all', // 语言
          // plugins: ['line-numbers', 'show-language', 'copy-to-clipboard', 'inline-color'],
          plugins: ['show-language', 'copy-to-clipboard', 'inline-color'],
          theme: 'solarizedlight', // 主题
          css: true
        })
        // Components({
        //   // 自动导入 AntDesignVue 组件
        //   resolvers: [AntDesignVueResolver()]
        // })
      ],
      server: {
        port: Number(env.RENDERER_VITE_PORT),
        // 开发环境跨域代理
        proxy:
          command === 'serve'
            ? {
                [env.RENDERER_VITE_BASE_API]: {
                  target: env.RENDERER_VITE_BASE_URL,
                  changeOrigin: true,
                  ws: true,
                  rewrite: (path) => path.replace(/^\/boot/, '')
                }
              }
            : {}
      }
    }
  }
})
